import { Message } from 'element-ui'
const jobWorkMixins = {
  // computed: {
  //   dapengUserId() {
  //     if (this.$store.state.user.dapengUserId) {
  //       return this.$store.state.user.dapengUserId
  //     } else {
  //       return this.$store.state.user.userId
  //     }
  //   }
  // },
  data() {
    return {
      loading: false,
      multipleSelection: [],
      tableData: [], // table内容
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      stance: '',
      isIndeterminate: false,
      checkAll: false, // 是否全选
      tableIds: [], // 当前列表全部id
      btnNum: [], // 点赞小手
      delDialogData: {
        isShow: false, // 默认隐藏
        type: '删除' // 类型
      },
      labelList: [], //隐性标签下拉列表
      labelListTotal: 0, //隐性标签总数
      canGetList: true, // 是否可以查询列表
      powerAry: [], // 可显示的权限
      canShowPage: false, // 是否显示当前页面
      dapengUserId: ''
    }
  },
  mounted() {
    let userInfo = localStorage.getItem('userInfo')
    userInfo = userInfo && JSON.parse(userInfo)
    const { dapengUserId, userId } = userInfo
    this.dapengUserId = dapengUserId || userId

    this.getVestLists()
    this.getLabelList()
  },
  methods: {
    /* 批量删除 */
    delAll() {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.delDialogData.isShow = true
      this.delDialogData.type = '删除'
    },
    /* 全选、全不选 */
    handleCheckAllChange(val) {
      this.multipleSelection = val ? this.tableIds : []
      this.isIndeterminate = false
    },
    /* 选中checkbox发生变化 */
    checkChange(value) {
      let checkedCount = value.length
      this.checkAll = checkedCount === this.tableIds.length
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.tableIds.length
    },
    /* 遍历获取当前页面table的id */
    checkTableId() {
      this.tableIds = []
      let _this = this
      this.tableData.forEach((item) => {
        if (item.jobcompletionId) {
          _this.tableIds.push(item.jobcompletionId)
        }
      })
    },
    refreshCheck() {
      this.checkAll = false
      this.isIndeterminate = false
      this.multipleSelection = []
    },
    /* 换页 */
    changePage() {
      this.refreshCheck()
      this.searchList()
    },
    /* 点赞后，刷新列表 */
    refresh() {
      this.searchList()
    },
    /* 搜索 */
    toSearch() {
      this.refreshCheck()
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /*获取当前用户马甲列表*/
    getVestLists() {
      let url = '/robots/options'
      this.pubRequire(
        'get',
        url,
        { userId: this.dapengUserId },
        (response) => {
          let vestList = response.rows
          this.$store.commit('setVestList', vestList)
        },
        (response) => {
          this.$store.commit('setVestList', [])
          Message.warning(response.message)
        }
      )
    },
    /*获取当前用户隐性标签列表*/
    getLabelList() {
      let url = '/content/labels/recommends/options'
      let obj = {
        pageNum: 1,
        pageSize: 30
      }
      this.pubRequire(
        'get',
        url,
        obj,
        (response) => {
          let labelList = response.rows
          this.labelListTotal = response.total
          labelList.forEach((item) => {
            item.disabled = false
            item.checked = false
          })
          this.labelList = JSON.parse(JSON.stringify(labelList))
        },
        (response) => {
          Message.warning(response.message)
        }
      )
    }
  }
}
export { jobWorkMixins }
